﻿$(document).ready(function () 
//This routine locked up all the anchor tags on the page
{
    $("a.helplink").click(function (e) 
    {
        e.preventDefault();               
        $('#myModal #contents').load($(this).attr('href'));
        $('#myModal').reveal();
    });   
});


// Functions for inch-centimeter calculations
function calcInchesToCentimeters(fieldin, fieldcm) {
    var inch = document.getElementById(fieldin);
    var cm = document.getElementById(fieldcm);
    cm.value = roundNumber(inch.value * 2.54, 1);
}

function calcCentimetersToInches(fieldin, fieldcm) {
    var inch = document.getElementById(fieldin);
    var cm = document.getElementById(fieldcm);
    inch.value = roundNumber(cm.value / 2.54, 1);
}

// Arguments: number to round, number of decimal places
function roundNumber(rnum, rlength) 
{ 
    var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10, rlength);
    return parseFloat(newnumber); // Output the result to the form field (change for your purposes)
}

// Function for BMI calculation
function calcBMI(heightft, heightin, weightlb, BMIfield) 
{
    var BMI = document.getElementById(BMIfield);
    var HeightIn = document.getElementById(heightin);
    var HeightFt = document.getElementById(heightft);
    var Weight = document.getElementById(weightlb);

    var heightininches = ((HeightFt.value * 12) + parseInt(HeightIn.value)) * ((HeightFt.value * 12) + parseInt(HeightIn.value));
    var weightmultiplied = (parseInt(Weight.value) * 703);

    BMI.value = roundNumber(weightmultiplied / heightininches, 1);

}
